from django.shortcuts import render
from rest_framework.generics import ListAPIView
# Create your views here.
from .serializers import BannerModelSerializer,NavModelSerializer
from .models import Banner,Nav
from django.utils import timezone as datetime
from renranapi.settings import constants

class BannerAPIView(ListAPIView):

    serializer_class = BannerModelSerializer
    #这里存在一个bug 为什么我们不将query_set 放在外面而是放在下面的方法内

    def get_queryset(self):
        '''我们将'''
        return Banner.objects.filter(
            is_deleted=False,
            is_show=True,
            start_time__lte=datetime.now(),
            end_time__gte=datetime.now(),
        ).order_by("orders","id")[:constants.HOME_BANNER_LENGTH]

class NavHEADERAPIView(ListAPIView):

    serializer_class = NavModelSerializer
    queryset = Nav.objects.filter(is_show=True,is_deleted=False,position=1,pid=None).order_by("orders","-id")[:constants.NAV_HEADER_LENGTH]

class NavFooterAPIView(ListAPIView):

    serializer_class = NavModelSerializer
    queryset = Nav.objects.filter(is_show=True,is_deleted=False,position=2,pid=None).order_by("orders","-id")[:constants.NAV_FOOTER_LENGTH]
